package localdatetime;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * ClassName:LocalDateTime
 * Package:localdatetime
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/22 - 16:54
 * @Version:v1.0
 */
public class LocalDateTimeTest {

    public static void main(String[] args) {
        //获取日期时间
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime);
        //获取年、月、日、时、分、秒
        System.out.println(dateTime.getYear());
        System.out.println(dateTime.getMonthValue());
        System.out.println(dateTime.getDayOfMonth());
        System.out.println(dateTime.getHour());
        System.out.println(dateTime.getMinute());
        System.out.println(dateTime.getSecond());

        //自定义日期时间
        LocalDateTime localDateTime = LocalDateTime.of(2023, 7, 22, 16, 58, 00);
        System.out.println(localDateTime);

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分钟ss秒");
        //2023年07月22日 17时03分钟25秒
        System.out.println(dateTimeFormatter.format(dateTime));
    }
}
